package com.dfbz.demo02_图片上传案例;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo01_Client {
    public static void main(String[] args) throws IOException {

        // 创建一个客户端,去连接服务器
        Socket socket = new Socket("192.168.31.90", 8888);

        // 获取与服务的输出流(将后续从磁盘中读取到的字节写入到服务器中)
        OutputStream os = socket.getOutputStream();

        // 从磁盘中读取文件
        FileInputStream fis = new FileInputStream("100.png");


        byte[] data = new byte[8192];

        int len;
        while ((len = fis.read(data)) != -1) {

            // 将从磁盘中读取到的字节写入到服务器中(文件上传)
            os.write(data, 0, len);
        }

        socket.close();
        fis.close();
    }
}
